<?php require VIEWPATH. ADMIN_DIR. DIRECTORY_SEPARATOR. 'header.php'?>
	<style type="text/css">
		.tree-branch-name .fa-check{background-color: #F9A021;border-color: #F9A021;color: #FFF;width: 15px;height: 15px;line-height: 15px;font-size: 11px;text-align: center;border-radius: 3px;position: relative;bottom: 1px;margin-right: 5px}
	</style>
	<div class="page-header">
		<h1><?=$articleInfo ? '修改文章' : '发布文章'?></h1>
	</div>
	<div class="col-xs-12">
		<form class="form-horizontal" id="teacher-form">
			<input type="hidden" name="id" value="<?=$articleInfo['id']?>" />
			<input type="hidden" name="article_cover" value="<?=$articleInfo['article_cover']?>" />
			<div class="form-group">
				<label class="col-sm-3 control-label no-padding-right">文章标题：</label>
				<div class="col-sm-6">
					<input class="form-control" type="text" name="article_title" placeholder="请填写文章标题" value="<?=$articleInfo['article_title']?>" />
				</div>
			</div>
			<div class="form-group">
				<label class="col-sm-3 control-label no-padding-right">文章封面：</label>
				<div class="col-sm-6">
					<a href="javascript:;" id="upload-img">
						<?php if($articleInfo['article_cover']): ?>
							<img class="fit-cover" src="<?=$articleInfo['article_cover']?>" width="160" height="160" />
						<?php else: ?>
							<img class="fit-cover" src="<?=$staticAdminUrl?>assets/images/upload.png" width="160" height="160" />
						<?php endif;?>
					</a>
				</div>
			</div>
			<div class="form-group">
				<label class="col-sm-3 control-label no-padding-right">文章分类：</label>
				<div class="col-sm-6">
					<select class="form-control" name="category_id">
						<?php foreach($categoryList as $category): ?>
							<option value="<?=$category['id']?>">
								<?=$category['parent_id'] ? "&nbsp;∟ " : ""?><?=$category['category_name']?>
							</option>
						<?php endforeach; ?>
					</select>
				</div>
			</div>
			<div class="form-group">
				<label class="col-sm-3 control-label no-padding-right">文章内容：</label>
				<div class="col-sm-6">
					<textarea class="pd0" id="content" name="article_content" style="height: 400px;width: 100%"><?=urldecode($articleInfo['article_content'])?></textarea>
				</div>
			</div>
			<div class="form-group">
				<label class="col-sm-3 control-label no-padding-right">文章排序：</label>
				<div class="col-sm-6">
					<input class="form-control" type="text" name="article_sort" placeholder="请填写文章排序" value="<?=$articleInfo['article_sort']?>" />
				</div>
			</div>
			<div class="clearfix">
				<div class="col-md-offset-3 col-md-9">
					<button class="btn btn-info" type="submit">
						<i class="ace-icon fa fa-check"></i> 提交
					</button>
				</div>
			</div>
		</form>
	</div>
<?php require VIEWPATH. ADMIN_DIR. DIRECTORY_SEPARATOR. 'footer.php'?>
<!-- 百度编辑器 -->
<script src="<?=$staticAdminUrl?>assets/ueditor/ueditor.config.js"></script>
<script src="<?=$staticAdminUrl?>assets/ueditor/ueditor.all.js"></script>
<script type="text/javascript">
	$(function(){
		var roleTree = $("#role-tree");
		var uploadTarget = $("#upload-img");
		var form = $("#teacher-form");


		// 修改教师
		<?php if($articleInfo): ?>
			$("[name=category_id]").val("<?=$articleInfo['category_id']?>");
		<?php endif; ?>

		// 初始化编辑器
		var ue = UE.getEditor('content');

		// 初始化头像上传插件
		setTimeout(function(){
			uploadTarget.uploader({
				"server":  '<?=UP_FORM_URL?>',
				"authorization": "<?=$signature?>",
				"policy": "<?=$policy?>",
				"callback": function(response) {
					var imgFile = "<?=UP_URL?>" + response.url;
					uploadTarget.find("img").attr("src", imgFile);
					form.find("[name=article_cover]").val(imgFile);
				}
			});
		}, 200)

		// 提交表单
		var submitUrl = "<?=admin_url('cms/save_article_action')?>";
		form_submit(form, submitUrl, function(res) {
			tips_alert(res.msg, res.success, function(){
				if(res.success) {
					window.location.href = "<?=admin_url('cms/index')?>";
				}
			});
		})
	})

	// 获取选中的权限菜单
	function set_selected_role_value(result){
		var selected = result.selected;
		var result = new Array();
		for(var i in selected) {
			var item = selected[i];
			result.push(item.attr.id);
		}
		$("[name=role_id_set]").val(result.join(","));
	}
</script>